<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Returns an ordinal scale for the specified domain. The arguments to this
<span class='line'>  3</span>  * constructor are optional, and equivalent to calling {@link #domain}.
<span class='line'>  4</span>  *
<span class='line'>  5</span>  * @class Represents an ordinal scale. &lt;style
<span class='line'>  6</span>  * type="text/css">sub{line-height:0}&lt;/style> An ordinal scale represents a
<span class='line'>  7</span>  * pairwise mapping from &lt;i>n&lt;/i> discrete values in the input domain to
<span class='line'>  8</span>  * &lt;i>n&lt;/i> discrete values in the output range. For example, an ordinal scale
<span class='line'>  9</span>  * might map a domain of species ["setosa", "versicolor", "virginica"] to colors
<span class='line'> 10</span>  * ["red", "green", "blue"]. Thus, saying
<span class='line'> 11</span>  *
<span class='line'> 12</span>  * &lt;pre>.fillStyle(function(d) {
<span class='line'> 13</span>  *     switch (d.species) {
<span class='line'> 14</span>  *       case "setosa": return "red";
<span class='line'> 15</span>  *       case "versicolor": return "green";
<span class='line'> 16</span>  *       case "virginica": return "blue";
<span class='line'> 17</span>  *     }
<span class='line'> 18</span>  *   })&lt;/pre>
<span class='line'> 19</span>  *
<span class='line'> 20</span>  * is equivalent to
<span class='line'> 21</span>  *
<span class='line'> 22</span>  * &lt;pre>.fillStyle(pv.Scale.ordinal("setosa", "versicolor", "virginica")
<span class='line'> 23</span>  *     .range("red", "green", "blue")
<span class='line'> 24</span>  *     .by(function(d) d.species))&lt;/pre>
<span class='line'> 25</span>  *
<span class='line'> 26</span>  * If the mapping from species to color does not need to be specified
<span class='line'> 27</span>  * explicitly, the domain can be omitted. In this case it will be inferred
<span class='line'> 28</span>  * lazily from the data:
<span class='line'> 29</span>  *
<span class='line'> 30</span>  * &lt;pre>.fillStyle(pv.colors("red", "green", "blue")
<span class='line'> 31</span>  *     .by(function(d) d.species))&lt;/pre>
<span class='line'> 32</span>  *
<span class='line'> 33</span>  * When the domain is inferred, the first time the scale is invoked, the first
<span class='line'> 34</span>  * element from the range will be returned. Subsequent calls with unique values
<span class='line'> 35</span>  * will return subsequent elements from the range. If the inferred domain grows
<span class='line'> 36</span>  * larger than the range, range values will be reused. However, it is strongly
<span class='line'> 37</span>  * recommended that the domain and the range contain the same number of
<span class='line'> 38</span>  * elements.
<span class='line'> 39</span>  *
<span class='line'> 40</span>  * &lt;p>A range can be discretized from a continuous interval (e.g., for pixel
<span class='line'> 41</span>  * positioning) by using {@link #split}, {@link #splitFlush} or
<span class='line'> 42</span>  * {@link #splitBanded} after the domain has been set. For example, if
<span class='line'> 43</span>  * &lt;tt>states&lt;/tt> is an array of the fifty U.S. state names, the state name can
<span class='line'> 44</span>  * be encoded in the left position:
<span class='line'> 45</span>  *
<span class='line'> 46</span>  * &lt;pre>.left(pv.Scale.ordinal(states)
<span class='line'> 47</span>  *     .split(0, 640)
<span class='line'> 48</span>  *     .by(function(d) d.state))&lt;/pre>
<span class='line'> 49</span>  *
<span class='line'> 50</span>  * &lt;p>N.B.: ordinal scales are not invertible (at least not yet), since the
<span class='line'> 51</span>  * domain and range and discontinuous. A workaround is to use a linear scale.
<span class='line'> 52</span>  *
<span class='line'> 53</span>  * @param {...} domain... domain values.
<span class='line'> 54</span>  * @returns {pv.Scale.ordinal} an ordinal scale.
<span class='line'> 55</span>  * @see pv.colors
<span class='line'> 56</span>  */</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="NAME">pv.Scale.ordinal</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">band</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> 
<span class='line'> 60</span> </span><span class="WHIT">  </span><span class="COMM">/** @private */</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">scale</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">x</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">d.push</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">r</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NAME">r.length</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 65</span> 
<span class='line'> 66</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 67</span>    * Sets or gets the input domain. This method can be invoked several ways:
<span class='line'> 68</span>    *
<span class='line'> 69</span>    * &lt;p>1. &lt;tt>domain(values...)&lt;/tt>
<span class='line'> 70</span>    *
<span class='line'> 71</span>    * &lt;p>Specifying the domain as a series of values is the most explicit and
<span class='line'> 72</span>    * recommended approach. However, if the domain values are derived from data,
<span class='line'> 73</span>    * you may find the second method more appropriate.
<span class='line'> 74</span>    *
<span class='line'> 75</span>    * &lt;p>2. &lt;tt>domain(array, f)&lt;/tt>
<span class='line'> 76</span>    *
<span class='line'> 77</span>    * &lt;p>Rather than enumerating the domain values as explicit arguments to this
<span class='line'> 78</span>    * method, you can specify a single argument of an array. In addition, you can
<span class='line'> 79</span>    * specify an optional accessor function to extract the domain values from the
<span class='line'> 80</span>    * array.
<span class='line'> 81</span>    *
<span class='line'> 82</span>    * &lt;p>3. &lt;tt>domain()&lt;/tt>
<span class='line'> 83</span>    *
<span class='line'> 84</span>    * &lt;p>Invoking the &lt;tt>domain&lt;/tt> method with no arguments returns the
<span class='line'> 85</span>    * current domain as an array.
<span class='line'> 86</span>    *
<span class='line'> 87</span>    * @function
<span class='line'> 88</span>    * @name pv.Scale.ordinal.prototype.domain
<span class='line'> 89</span>    * @param {...} domain... domain values.
<span class='line'> 90</span>    * @returns {pv.Scale.ordinal} &lt;tt>this&lt;/tt>, or the current domain.
<span class='line'> 91</span>    */</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">  </span><span class="NAME">scale.domain</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">array</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">      </span><span class="NAME">array</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">array</span><span class="WHIT"> </span><span class="KEYW">instanceof</span><span class="WHIT"> </span><span class="NAME">Array</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">          </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">map</span><span class="PUNC">(</span><span class="NAME">array</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">array</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">          </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Array.prototype.slice.call</span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 97</span> 
<span class='line'> 98</span> </span><span class="WHIT">      </span><span class="COMM">/* Filter the specified ordinals to their unique values. */</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT">      </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">seen</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">      </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">array.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">array</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">o</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">seen</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">          </span><span class="NAME">seen</span><span class="PUNC">[</span><span class="NAME">o</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">          </span><span class="NAME">d.push</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>108</span> 
<span class='line'>109</span> </span><span class="WHIT">      </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.numerate</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>114</span> 
<span class='line'>115</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>116</span>    * Sets or gets the output range. This method can be invoked several ways:
<span class='line'>117</span>    *
<span class='line'>118</span>    * &lt;p>1. &lt;tt>range(values...)&lt;/tt>
<span class='line'>119</span>    *
<span class='line'>120</span>    * &lt;p>Specifying the range as a series of values is the most explicit and
<span class='line'>121</span>    * recommended approach. However, if the range values are derived from data,
<span class='line'>122</span>    * you may find the second method more appropriate.
<span class='line'>123</span>    *
<span class='line'>124</span>    * &lt;p>2. &lt;tt>range(array, f)&lt;/tt>
<span class='line'>125</span>    *
<span class='line'>126</span>    * &lt;p>Rather than enumerating the range values as explicit arguments to this
<span class='line'>127</span>    * method, you can specify a single argument of an array. In addition, you can
<span class='line'>128</span>    * specify an optional accessor function to extract the range values from the
<span class='line'>129</span>    * array.
<span class='line'>130</span>    *
<span class='line'>131</span>    * &lt;p>3. &lt;tt>range()&lt;/tt>
<span class='line'>132</span>    *
<span class='line'>133</span>    * &lt;p>Invoking the &lt;tt>range&lt;/tt> method with no arguments returns the
<span class='line'>134</span>    * current range as an array.
<span class='line'>135</span>    *
<span class='line'>136</span>    * @function
<span class='line'>137</span>    * @name pv.Scale.ordinal.prototype.range
<span class='line'>138</span>    * @param {...} range... range values.
<span class='line'>139</span>    * @returns {pv.Scale.ordinal} &lt;tt>this&lt;/tt>, or the current range.
<span class='line'>140</span>    */</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">  </span><span class="NAME">scale.range</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">array</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">      </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">array</span><span class="WHIT"> </span><span class="KEYW">instanceof</span><span class="WHIT"> </span><span class="NAME">Array</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">          </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">map</span><span class="PUNC">(</span><span class="NAME">array</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">array</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT">          </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Array.prototype.slice.call</span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">r</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">r.map</span><span class="PUNC">(</span><span class="NAME">pv.color</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">r</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> 
<span class='line'>152</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>153</span>    * Sets the range from the given continuous interval. The interval
<span class='line'>154</span>    * [&lt;i>min&lt;/i>, &lt;i>max&lt;/i>] is subdivided into &lt;i>n&lt;/i> equispaced points,
<span class='line'>155</span>    * where &lt;i>n&lt;/i> is the number of (unique) values in the domain. The first
<span class='line'>156</span>    * and last point are offset from the edge of the range by half the distance
<span class='line'>157</span>    * between points.
<span class='line'>158</span>    *
<span class='line'>159</span>    * &lt;p>This method must be called &lt;i>after&lt;/i> the domain is set.
<span class='line'>160</span>    *
<span class='line'>161</span>    * @function
<span class='line'>162</span>    * @name pv.Scale.ordinal.prototype.split
<span class='line'>163</span>    * @param {number} min minimum value of the output range.
<span class='line'>164</span>    * @param {number} max maximum value of the output range.
<span class='line'>165</span>    * @returns {pv.Scale.ordinal} &lt;tt>this&lt;/tt>.
<span class='line'>166</span>    * @see #splitFlush
<span class='line'>167</span>    * @see #splitBanded
<span class='line'>168</span>    */</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">  </span><span class="NAME">scale.split</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">max</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">min</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">this.domain</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">    </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.range</span><span class="PUNC">(</span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">step</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>174</span> 
<span class='line'>175</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>176</span>    * Sets the range from the given continuous interval. The interval
<span class='line'>177</span>    * [&lt;i>min&lt;/i>, &lt;i>max&lt;/i>] is subdivided into &lt;i>n&lt;/i> equispaced points,
<span class='line'>178</span>    * where &lt;i>n&lt;/i> is the number of (unique) values in the domain. The first
<span class='line'>179</span>    * and last point are exactly on the edge of the range.
<span class='line'>180</span>    *
<span class='line'>181</span>    * &lt;p>This method must be called &lt;i>after&lt;/i> the domain is set.
<span class='line'>182</span>    *
<span class='line'>183</span>    * @function
<span class='line'>184</span>    * @name pv.Scale.ordinal.prototype.splitFlush
<span class='line'>185</span>    * @param {number} min minimum value of the output range.
<span class='line'>186</span>    * @param {number} max maximum value of the output range.
<span class='line'>187</span>    * @returns {pv.Scale.ordinal} &lt;tt>this&lt;/tt>.
<span class='line'>188</span>    * @see #split
<span class='line'>189</span>    */</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">  </span><span class="NAME">scale.splitFlush</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.domain</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">max</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">min</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">    </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">(</span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">]</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">        </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">pv.range</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">step</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>196</span> 
<span class='line'>197</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>198</span>    * Sets the range from the given continuous interval. The interval
<span class='line'>199</span>    * [&lt;i>min&lt;/i>, &lt;i>max&lt;/i>] is subdivided into &lt;i>n&lt;/i> equispaced bands,
<span class='line'>200</span>    * where &lt;i>n&lt;/i> is the number of (unique) values in the domain. The first
<span class='line'>201</span>    * and last band are offset from the edge of the range by the distance between
<span class='line'>202</span>    * bands.
<span class='line'>203</span>    *
<span class='line'>204</span>    * &lt;p>The band width argument, &lt;tt>band&lt;/tt>, is typically in the range [0, 1]
<span class='line'>205</span>    * and defaults to 1. This fraction corresponds to the amount of space in the
<span class='line'>206</span>    * range to allocate to the bands, as opposed to padding. A value of 0.5 means
<span class='line'>207</span>    * that the band width will be equal to the padding width. The computed
<span class='line'>208</span>    * absolute band width can be retrieved from the range as
<span class='line'>209</span>    * &lt;tt>scale.range().band&lt;/tt>.
<span class='line'>210</span>    *
<span class='line'>211</span>    * &lt;p>If the band width argument is negative, this method will allocate bands
<span class='line'>212</span>    * of a &lt;i>fixed&lt;/i> width &lt;tt>-band&lt;/tt>, rather than a relative fraction of
<span class='line'>213</span>    * the available space.
<span class='line'>214</span>    *
<span class='line'>215</span>    * &lt;p>Tip: to inset the bands by a fixed amount &lt;tt>p&lt;/tt>, specify a minimum
<span class='line'>216</span>    * value of &lt;tt>min + p&lt;/tt> (or simply &lt;tt>p&lt;/tt>, if &lt;tt>min&lt;/tt> is
<span class='line'>217</span>    * 0). Then set the mark width to &lt;tt>scale.range().band - p&lt;/tt>.
<span class='line'>218</span>    *
<span class='line'>219</span>    * &lt;p>This method must be called &lt;i>after&lt;/i> the domain is set.
<span class='line'>220</span>    *
<span class='line'>221</span>    * @function
<span class='line'>222</span>    * @name pv.Scale.ordinal.prototype.splitBanded
<span class='line'>223</span>    * @param {number} min minimum value of the output range.
<span class='line'>224</span>    * @param {number} max maximum value of the output range.
<span class='line'>225</span>    * @param {number} [band] the fractional band width in [0, 1]; defaults to 1.
<span class='line'>226</span>    * @returns {pv.Scale.ordinal} &lt;tt>this&lt;/tt>.
<span class='line'>227</span>    * @see #split
<span class='line'>228</span>    */</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">  </span><span class="NAME">scale.splitBanded</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">band</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">band</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">band</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.domain</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">          </span><span class="NAME">total</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NAME">band</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>234</span> </span><span class="WHIT">          </span><span class="NAME">remaining</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">max</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">total</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>235</span> </span><span class="WHIT">          </span><span class="NAME">padding</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">remaining</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">      </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.range</span><span class="PUNC">(</span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">padding</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">padding</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">band</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">      </span><span class="NAME">r.band</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NAME">band</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">max</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">min</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.domain</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">band</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">      </span><span class="NAME">r</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.range</span><span class="PUNC">(</span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">band</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">step</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">      </span><span class="NAME">r.band</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">step</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">band</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>245</span> 
<span class='line'>246</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>247</span>    * Returns a view of this scale by the specified accessor function &lt;tt>f&lt;/tt>.
<span class='line'>248</span>    * Given a scale &lt;tt>y&lt;/tt>, &lt;tt>y.by(function(d) d.foo)&lt;/tt> is equivalent to
<span class='line'>249</span>    * &lt;tt>function(d) y(d.foo)&lt;/tt>. This method should be used judiciously; it
<span class='line'>250</span>    * is typically more clear to invoke the scale directly, passing in the value
<span class='line'>251</span>    * to be scaled.
<span class='line'>252</span>    *
<span class='line'>253</span>    * @function
<span class='line'>254</span>    * @name pv.Scale.ordinal.prototype.by
<span class='line'>255</span>    * @param {function} f an accessor function.
<span class='line'>256</span>    * @returns {pv.Scale.ordinal} a view of this scale by the specified accessor
<span class='line'>257</span>    * function.
<span class='line'>258</span>    */</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">  </span><span class="NAME">scale.by</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">by</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">scale</span><span class="PUNC">(</span><span class="NAME">f.apply</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">method</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">scale</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">by</span><span class="PUNC">[</span><span class="NAME">method</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">scale</span><span class="PUNC">[</span><span class="NAME">method</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">by</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>264</span> 
<span class='line'>265</span> </span><span class="WHIT">  </span><span class="NAME">scale.domain.apply</span><span class="PUNC">(</span><span class="NAME">scale</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">scale</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>267</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>268</span> </span></pre></body></html>